<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:ui="http://java.sun.com/jsf/facelets"   
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>#{bundle.glaccnt}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form >
           <script type="text/javascript">  
                function handleSaveGlAccount(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgGlaccnt.hide();  
                    }  
                }
                
                function handleDeleteGlAccount(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgDelGLaccnt.hide();  
                    }  
                }
                
            </script>  

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     icon="ui-icon-document" rendered="#{menuBean.cekButtonAccess(563,'INS;')}"
                                     action="#{glaccntBean.newData()}"  
                                     oncomplete="dlgGlaccnt.show()" process="@this"
                                     update=":#{utilityBean.findClientId('displayGlaccnt')}"> 
                        <pe:resetEditableValues for="displayGlaccnt" />
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgGlaccnt.show()"
                                     icon="ui-icon-disk" action="#{glaccntBean.openData()}"  rendered="#{menuBean.cekButtonAccess(563,'OPN;')}"
                                     update=":#{utilityBean.findClientId('displayGlaccnt')}" > 
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnDelete}" icon="ui-icon-trash"
                                    rendered="#{menuBean.cekButtonAccess(563,'DEL;')}"
                                     onclick="dlgDelGLaccnt.show()" /> 

                    <!--<p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/>-->
                </p:toolbarGroup>
            </p:toolbar>
            <br />
        <!--    <p:dataTable var="glaccnt" value="#{glaccntBean.glaccnts}" id="dtGlaccnts"
                         selection="#{glaccntBean.selectedData}" selectionMode="single" 
                         rowIndexVar="noUrut" rowKey="#{glaccnt.glaccntId}" sortBy="#{glaccnt.accountName}"
                         paginator="true" rows="10" paginatorPosition="bottom" resizableColumns="true"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="10,15,30">
                 <p:column style="width: 11px;">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                 </p:column>
                <p:column style="width:30px;" sortBy="#{bundle.accountNo}">
                    <f:facet name="header">#{bundle.accountNo}</f:facet>
                    <h:outputText value="#{glaccnt.accountNo}" />
                </p:column>
                <p:column style="width:auto" sortBy="#{glaccnt.accountName}">
                    <f:facet name="header">#{bundle.globalName}</f:facet>
                    <h:outputText value="#{glaccnt.accountName}" />
                </p:column>
                <p:column style="width:100px;">
                    <f:facet name="header">#{bundle.accountType}</f:facet>
                    <h:outputText value="#{glaccntBean.getAccTypeText(glaccnt.accountType)}" />
                </p:column>
                 <p:column style="width:100px;">
                    <f:facet name="header">#{bundle.parent}</f:facet>
                    <h:outputText value="#{glaccntBean.selectItemValueOf(glaccnt.parentGlaccntId)}" />
                </p:column>
              
                <p:column style="width:30px;" >
                    <f:facet name="header">#{bundle.suspended}</f:facet>
                    <h:selectBooleanCheckbox value="#{glaccnt.suspended}" disabled="true"/>
                </p:column>
            </p:dataTable> -->
            <p:treeTable id="dtGlaccnts" value="#{glaccntBean.rootNode}" var="node" selectionMode="single"
                         selection="#{glaccntBean.selectedNode}">                    
                    <p:column style="width:150px"> 
                        <f:facet name="header">  
                        #{bundle.globalCode}  
                    </f:facet>  
                    <h:outputText value="#{node.accountNo}" />  
                    </p:column>
                <p:column style="width:150px"> 
                        <f:facet name="header">  
                        #{bundle.globalName}  
                    </f:facet>  
                    <h:outputText value="#{node.accountName}" />  
                    </p:column>
					<p:column style="width:150px"> 
                        <f:facet name="header">  
                        #{bundle.accountType}  
                    </f:facet>  
                    <h:outputText value="#{glaccntBean.getAccTypeText(node.accountType)}" />  
                    </p:column>
					<p:column style="width:150px"> 
                        <f:facet name="header">  
                        #{bundle.parent}  
                    </f:facet>  
                    <h:outputText value="#{glaccntBean.selectItemValueOf(node.parentGlaccntId)}" />  
                    </p:column>
					<p:column style="width:150px"> 
                        <f:facet name="header">  
                        #{bundle.suspended}  
                    </f:facet>  
                       <h:selectBooleanCheckbox value="#{node.suspended}" disabled="true"/>
                    </p:column>
            </p:treeTable>            
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDelGLaccnt">  
                <p:commandButton value="#{bundle.btnYes}" update="dtGlaccnts" process="@this"
                                 oncomplete="handleDeleteGlAccount(xhr, status, args)"  
                                 actionListener="#{glaccntBean.delete()}" />  
                <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDelGLaccnt.hide()" type="button" />   
            </p:confirmDialog> 

        </h:form>
            <p:dialog header="#{bundle.glaccnt}" widgetVar="dlgGlaccnt" closable="true"
                      dynamic="true" modal="true" appendToBody="true">
                <p:ajax event="close" listener="#{glaccntBean.handleClose}" immediate="true"/>
                <h:form>
                <h:panelGrid id="displayGlaccnt" columns="3" styleClass="addELIT" >
                    <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.parent}" /><h:outputLabel value= ":" />
                    <p:selectOneMenu rendered="#{glaccntBean.insertedData!=null}" value="#{glaccntBean.insertedData.parentGlaccntId}" style="width: 150px"> 
                        <f:selectItem itemLabel="#{bundle.Select} #{bundle.parent}" itemValue="-1"/>
                        <f:selectItems value="#{glaccntBean.avblGL}"/> 
                    </p:selectOneMenu>
                    
                    <h:outputLabel value= "#{bundle.accountNo}" /><h:outputLabel value= ":" />
                    <p:inputText rendered="#{glaccntBean.insertedData!=null}" value="#{glaccntBean.insertedData.accountNo}" 
                                     required="true" label="#{bundle.accountNo}"  style="width: 50px;" />
                   <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                   <p:inputText rendered="#{glaccntBean.insertedData!=null}" value="#{glaccntBean.insertedData.accountName}" 
                                     required="true" label="#{bundle.accountName}" style="width: 150px;" />
                    
                    <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.accountType}" /><h:outputLabel value= ":" />
                    <p:selectOneMenu rendered="#{glaccntBean.insertedData!=null}" value="#{glaccntBean.insertedData.accountType}" style="width: 150px"> 
                        <f:selectItems value="#{glaccntBean.avblAcctype}"/> 
                    </p:selectOneMenu>
                    
                    <h:outputLabel value= "#{bundle.suspended}" /> <h:outputLabel value= ":" />
                    <p:selectBooleanCheckbox rendered="#{glaccntBean.insertedData!=null}" value="#{glaccntBean.insertedData.suspended}" />  
                </h:panelGrid>
              
                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{glaccntBean.trySave()}"  rendered="#{menuBean.cekButtonAccess(563,'UPD;')}"
                                         update=":#{utilityBean.findClientId('dtGlaccnts')}"
                                         oncomplete="handleSaveGlAccount(xhr, status, args)"/>
                        <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgGlaccnt.hide()" immediate="true" icon="ui-icon-document"/>
                    </f:facet>
                </h:panelGrid>
                        </h:form>
            </p:dialog> 
        </ui:composition>    
    </h:body>
</html>
